package com.algorithm3;

import java.util.Arrays;

public class InsertionSort {
    public static void sort(int[] array) {
       for(int i=0;i<array.length-1;i++){
           int j = i+1;
           int temp = array[j];
           while(j>0&&array[j-1]<temp ){
                array[j] = array[j-1];
                j--;
           }
           array[j] = temp;
           System.out.println("排序:"+i+"-->"+ Arrays.toString(array));
       }
    }
    public static void swap(int[] array,int i,int j){
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }

    public static void main(String[] args){
        int[] array = new int[]{5,7,6,8,9,3,2,4,1,10};
        System.out.println("排序前:"+ Arrays.toString(array));
        sort(array);
        System.out.println("排序后:"+ Arrays.toString(array));
    }

}
